package com.net.loaderManage.item
{
    import com.net.loaderManage.consumer.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.system.*;

    public class LoaderItem extends Object
    {
        private var _url:String;
        private var _loader:Loader;
        private var _consumer:ILoaderItemConsumer;

        public function LoaderItem(param1:String, param2:ILoaderItemConsumer)
        {
            _url = param1;
            _consumer = param2;
            var _loc_3:* = new LoaderContext(true);
            _loader = new Loader();
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandle);
            _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandle);
            _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandle);
            if (_url == null || _url == "")
            {
                return;
            }
            _loader.load(new URLRequest(param1), _loc_3);
            return;
        }// end function

        private function completeHandle(event:Event) : void
        {
            if (_consumer)
            {
                _consumer.receiveLoader(_loader);
            }
            _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandle);
            _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorHandle);
            _loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandle);
            _loader = null;
            return;
        }// end function

        public function loader() : Loader
        {
            return _loader;
        }// end function

        private function progressHandle(event:ProgressEvent) : void
        {
            return;
        }// end function

        private function errorHandle(event:IOErrorEvent) : void
        {
            if (_consumer)
            {
                _consumer.errorHandle(event);
            }
            _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandle);
            _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorHandle);
            _loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandle);
            _loader = null;
            return;
        }// end function

    }
}
